require "net/http"

print "Enter CatchEx authentication information.\n"
print "Username: "
username = STDIN.gets

print "Password: "
password = STDIN.gets

http = Net::HTTP.new("localhost", 3000)
req = Net::HTTP::Get.new("/auth")
req.basic_auth username.strip, password.strip
response = http.request(req)

if response.code == "200"
  File.open("#{File.dirname(__FILE__)}/../../../config/catchex.key", "w") do |file|
    file << response.body
  end
else
  print response.body
end